package com.ibuonline.utils;

import java.util.ArrayList;
import java.util.List;

import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.SpelNode;
import org.springframework.expression.spel.ast.PropertyOrFieldReference;
import org.springframework.expression.spel.standard.SpelExpression;
import org.springframework.expression.spel.standard.SpelExpressionParser;

import com.greenpineyu.fel.FelEngine;
import com.greenpineyu.fel.FelEngineImpl;
import com.greenpineyu.fel.parser.AbstFelNode;
import com.greenpineyu.fel.parser.FelNode;
import com.greenpineyu.fel.parser.VarAstNode;

public class ExpressionUtils {
	/**
	 * 获取表达式中的变量
	 * 
	 * @param exp
	 *            表达式
	 * @return 变量列表
	 */
	public static List<String> getVars(String exp) {
		List<String> vars = new ArrayList<String>();
		FelEngine engine = new FelEngineImpl();
		FelNode node = engine.parse(exp);
		List<FelNode> nodes = AbstFelNode.getNodes(node);
		for (FelNode n : nodes) {
			if (n instanceof VarAstNode) {
				vars.add(n.getText());
			}
		}
		return vars;
	}
}
